package com.hualan.sfzyproject.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hualan.sfzyproject.domain.FeaturedArticle;
import com.hualan.sfzyproject.mapper.FeaturedArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FeaturedArticleService {
    @Autowired
    private FeaturedArticleMapper featuredArticleMapper;

    public int insert(FeaturedArticle featuredArticle) {
        return featuredArticleMapper.insert(featuredArticle);
    }

    public int update(FeaturedArticle featuredArticle) {
        return featuredArticleMapper.updateByPrimaryKeySelective(featuredArticle);
    }

    public int delete(Long id) {
        return featuredArticleMapper.deleteByPrimaryKey(id);
    }

    public FeaturedArticle selectById(Long id) {
        return featuredArticleMapper.selectByPrimaryKey(id);
    }

    public List<FeaturedArticle> selectByConsultantId(int consultantId) {
        return featuredArticleMapper.selectByConsultantId(consultantId);
    }

    public List<FeaturedArticle> selectAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<FeaturedArticle> featuredArticles = featuredArticleMapper.selectAll();
        PageInfo<FeaturedArticle> pageInfo = new PageInfo<>(featuredArticles);
        if (pageInfo.getPages() < pageNum) {
            return null;
        }
        featuredArticles = pageInfo.getList();
        return featuredArticles;
    }




}
